 /*****************************************************************************
* Copyright (c) 2009
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Angelo Zerr <angelo.zerr@gmail.com>
*     Pascal Leclercq <pascal.leclercq@gmail.com>
*******************************************************************************/

package org.dynaresume.remoting.http;

import java.lang.reflect.InvocationTargetException;

import net.sf.beanlib.hibernate.HibernateBeanReplicator;
import net.sf.beanlib.hibernate3.Hibernate3BeanReplicator;
import net.sf.beanlib.hibernate3.LazyHibernateCustomBeanTransformer;

import org.springframework.remoting.support.DefaultRemoteInvocationExecutor;
import org.springframework.remoting.support.RemoteInvocation;

public class RemoteInvocationExecutor extends DefaultRemoteInvocationExecutor {
	
	HibernateBeanReplicator replicator = new Hibernate3BeanReplicator().initCustomTransformerFactory(new LazyHibernateCustomBeanTransformer.Factory());;
	
	public RemoteInvocationExecutor() {

	}

	@Override
	public Object invoke(RemoteInvocation invocation, Object targetObject)
			throws NoSuchMethodException, IllegalAccessException,
			InvocationTargetException {
//		System.out.println(invocation);
		Object fromBean =null;
		try{
		 fromBean = super.invoke(invocation, targetObject);
		}catch (Throwable t){
			t.printStackTrace();
		}
		Object toBean = replicator.copy(fromBean);
		return toBean;
	}
}
